package com.medical.data.annotationImpl;

import com.medical.data.annotations.FormItemTypeValidate;
import com.medical.data.constEnum.FormItemEnum;
import com.medical.data.utils.ResetMessageUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.ObjectUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class FormItemTypeValidateImpl implements ConstraintValidator<FormItemTypeValidate, String> {

    @Override
    public void initialize(FormItemTypeValidate constraintAnnotation) {
        ConstraintValidator.super.initialize(constraintAnnotation);
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
       if (StringUtils.isBlank(value)){
           ResetMessageUtil.reset(context, "表单类型不能为空");
           return false;
       }

        if (ObjectUtils.isEmpty(FormItemEnum.getFormItemEnum(value))){
           return false;
       }
       return true;
    }


}
